package com.crape.message.dao.impl;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import com.crape.common.exceptions.DAOException;
import com.crape.common.ibatis.SqlMapClientDaoSupportEx;
import com.crape.common.model.MsgUser;
import com.crape.message.dao.IMsgUserDAO;

public class MsgUserDAOImpl extends SqlMapClientDaoSupportEx implements IMsgUserDAO {

	@Override
	public MsgUser getMsgUserById(Long id) throws DAOException {
		if (id == null) {
			return null;
		}
		return (MsgUser) this.queryObject("getMsgUserById", id);
	}

	@SuppressWarnings("unchecked")
	@Override
	public List<MsgUser> getPagedMsgInfos(Long receiveid, Long sendid, Integer startIndex, Integer pageSize) throws DAOException {
		if (receiveid == null || sendid == null || pageSize == null || pageSize == 0) {
			return null;
		}
		Map<String, Object> params = new HashMap<String, Object>();
		params.put("receiveid", receiveid);
		params.put("sendid", sendid);
		params.put("startIndex", startIndex);
		params.put("pageSize", pageSize);
		return (List<MsgUser>) this.queryList("getPagedMsgInfos", params);
	}

	@Override
	public Long countMsgInfos(Long receiveid, Long sendid) throws DAOException {
		if (receiveid == null || sendid == null) {
			return 0L;
		}
		Map<String, Object> params = new HashMap<String, Object>();
		params.put("receiveid", receiveid);
		params.put("sendid", sendid);
		return (Long) this.queryObject("countMsgInfos", params);
	}

	@SuppressWarnings("unchecked")
	@Override
	public List<MsgUser> getPagedReceivedMsgs(Long receiveid, Integer startIndex, Integer pageSize) throws DAOException {
		if (receiveid == null || startIndex == null || pageSize == null || pageSize == 0) {
			return null;
		}
		Map<String, Object> params = new HashMap<String, Object>();
		params.put("receiveid", receiveid);
		params.put("startIndex", startIndex);
		params.put("pageSize", pageSize);
		return (List<MsgUser>) this.queryList("getPagedReceivedMsgs", params);
	}

	@Override
	public Long countReceivedMsgs(Long receiveid) throws DAOException {
		if (receiveid == null) {
			return 0L;
		}
		return (Long) this.queryObject("countReceivedMsgs", receiveid);
	}

	@SuppressWarnings("unchecked")
	@Override
	public List<MsgUser> getPagedSendedMsgs(Long sendid, Integer startIndex, Integer pageSize) throws DAOException {
		if (sendid == null || startIndex == null || pageSize == null || pageSize == 0) {
			return null;
		}
		Map<String, Object> params = new HashMap<String, Object>();
		params.put("sendid", sendid);
		params.put("startIndex", startIndex);
		params.put("pageSize", pageSize);
		return (List<MsgUser>) this.queryList("getPagedSendedMsgs", params);
	}

	@Override
	public Long countSendedMsgs(Long sendid) throws DAOException {
		if (sendid == null) {
			return 0L;
		}
		return (Long) this.queryObject("countSendedMsgs", sendid);
	}

	@Override
	public void insertMsgUser(MsgUser msgUser) throws DAOException {
		if (msgUser == null) {
			return;
		}
		this.insert("insertMsgUser", msgUser);
	}

	@Override
	public void deleteMsgUserById(Long id) throws DAOException {
		if (id == null) {
			return;
		}
		this.delete("deleteMsgUserById", id);
	}

}
